#include "mat.h"
#include "opencv2/opencv.hpp"
#include <iostream>
#include <vector>
#include "net.h"

#define TEST 0

#if TEST==1
// #include "alexnet.id.h"
#include "alexnet.mem.h"
#endif

int main(void){
    ncnn::Net net;
#if TEST==0
    net.load_param("../../model/alexnet.param");
    net.load_model("../../model/alexnet.bin");
#elif TEST==1
    net.load_param(alexnet_param_bin);
    net.load_model(alexnet_bin);
#endif
    int w = 227;
    int h = 227;
    ncnn::Mat in;
    ncnn::Mat out;

    cv::Mat srcImg = cv::imread("../../model/img/test1.jpg");

    // ncnn的输入尺寸需要和模型尺寸一致，它内部不会自动转化
    cv::resize(srcImg,srcImg,cv::Size(227,227));

    // OpenCV默认的格式是BGR格式
    in = ncnn::Mat::from_pixels(srcImg.data,ncnn::Mat::PIXEL_BGR2RGB,srcImg.cols,srcImg.rows);

    // 这三个均值是在训练的时候给出的，
    const float mean_vals[3] = {104.f, 117.f, 123.f};
    in.substract_mean_normalize(mean_vals, 0);

    ncnn::Extractor ex = net.create_extractor();
    ex.set_light_mode(true);
    ex.input("actual_input_1",in);
    ex.extract("output1",out);

    ncnn::Mat out_flatterned = out.reshape(out.w * out.h * out.c);
    std::vector<float> scores;
    scores.resize(out_flatterned.w);
    for (int j=0; j<out_flatterned.w; j++)
    {
        scores[j] = out_flatterned[j];
        // std::cout << scores[j] << std::endl;
    }

    net.clear();

    std::cout << scores.size() << std ::endl;

    return 0;
}
